package tk.hoopy.zedtown.input;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class KeyboardInput implements KeyListener {
	
	public static final int 
		LEFT  = 0,
		RIGHT = 1,
		UP    = 2,
		DOWN  = 3;
	
	private boolean keyStates[] = new boolean[4];

	@Override
	public void keyPressed(KeyEvent e) {
		switch(e.getKeyCode()) {
			case(KeyEvent.VK_LEFT):
				keyStates[LEFT] = true;
				return;
			case(KeyEvent.VK_RIGHT):
				keyStates[RIGHT] = true;
				return;
			case(KeyEvent.VK_UP):
				keyStates[UP] = true;
				return;
			case(KeyEvent.VK_DOWN):
				keyStates[DOWN] = true;
				return;
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		switch(e.getKeyCode()) {
			case(KeyEvent.VK_LEFT):
				keyStates[LEFT] = false;
				return;
			case(KeyEvent.VK_RIGHT):
				keyStates[RIGHT] = false;
				return;
			case(KeyEvent.VK_UP):
				keyStates[UP] = false;
				return;
			case(KeyEvent.VK_DOWN):
				keyStates[DOWN] = false;
				return;
		}
	}

	@Override
	public void keyTyped(KeyEvent e) {
		
	}
	
	public boolean GetKeyState(int key) {
		return keyStates[key];
	}

}
